<template>
  <div class="detail-result">
    <div class="card-title">
      <h3>成果信息</h3>
    </div>
    <div class="card-table">
      <el-table
        :data="list"
        :span-method="objectSpanMethod"
        element-loading-text="正在查询中。。。"
        border
        fit
        highlight-current-row
      >
        <el-table-column align="center" label="所属模块" prop="owningModule">
          <template slot-scope="scope">
            <span>{{ modelListOptionsMap[scope.row.owningModule] }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="（起始）年度" prop="resYear" />
        <el-table-column align="center" label="成果名称" prop="resName" />
        <el-table-column
          align="center"
          label="验收/发布途径"
          prop="resAuthAgency"
        />
        <el-table-column align="center" label="类别" prop="resType">
        </el-table-column>
        <el-table-column align="center" label="级别" prop="resLevel" />
        <el-table-column
          align="center"
          label="负责人名称"
          prop="dutyPersonalName"
        />
        <el-table-column align="center" label="备注信息" prop="resRemark" />
      </el-table>
    </div>
  </div>
</template>
<script>
import { modelListOptionsMap } from '@/utils/commonData'
export default {
  data() {
    return {
      modelListOptionsMap,
      list: [],
      rowSpanArr: []
    }
  },
  methods: {
    init(listMap) {
      this.list = []
      Object.keys(listMap).forEach((el) => {
        this.list = [...this.list, ...listMap[el]]
      })
      this.rowSpanArr = []
      let itemIndex = 0
      this.list.forEach((el, index) => {
        if (index == 0) {
          this.rowSpanArr.push(1)
        } else {
          if (
            this.list[index].owningModule == this.list[index - 1].owningModule
          ) {
            this.rowSpanArr[itemIndex] += 1 // 项目名称相同，合并到同一个数组中
            this.rowSpanArr.push(0)
          } else {
            this.rowSpanArr.push(1)
            itemIndex = index
          }
        }
      })
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        const _row = this.rowSpanArr[rowIndex]
        return {
          rowspan: _row, // 行
          colspan: 1 // 列
        }
      }
    }
  }
}
</script>
